
/**
* 基本信息验证
*/
function validate(){
	if(!checkFormTag($("#nameInput"))){
		goToPosition("nameInput");
		return false;
	}else if(!checkFormTag($("#jobTypeInput"))){
		goToPosition("nameInput");
		return false;
	}else if(!checkProvince()){
		goToPosition("s_province");
		return false;
	}else if(!checkCity()){
		goToPosition("s_province");
		return false;
	}else if(!checkFormTag($("#addressInput"))){
		goToPosition("addressInput");
		return false;
	}else if(!checkFormTag($("#companyInput"))){
		goToPosition("companyInput");
		return false;
	}else if(!checkFormTag($("#departmentInput"))){
		goToPosition("departmentInput");
		return false;
	}else if(!checkFormNumber($("#salary_min"))){
		goToPosition("salary_min");
		return false;
	}else if(!checkFormNumber($("#salary_max"))){
		goToPosition("salary_max");
		return false;
	}else if(!checkSalary()){
		goToPosition("salary_min");
		return false;
	}else if(!checkFormTag($("#team_introInput"))){
		goToPosition("team_introInput");
		return false;
	}else if(!checkFormTag($("#responsibilityInput"))){
		goToPosition("team_introInput");
		return false;
	}else
		return true;
}

function checkSalary(){
	var min = parseInt($("#salary_min").val());
	var max = parseInt($("#salary_max").val());
	if(max<min){
		$("#salary_max").addClass("ipt-txt-error");
		$("#salaryTips").html("请填写有效月薪范围");
		$("#salaryTips").removeClass().addClass("form-tips form-tips-error");
	 	return false;
	}else
		return true;
}

function checkProvince(){
	var checkObj = $("#s_province");
	var province =checkObj.val();
	var _tips =  $("#pcTips");
	if(province==''){
		checkObj.addClass("ipt-txt-error");
		 _tips.html(checkObj.attr("tips"));
		 _tips.removeClass().addClass("form-tips form-tips-error");
	 	return false;
	}else{
		 _tips.html("");
		 checkObj.removeClass("ipt-txt-error");
		 _tips.removeClass().addClass("form-tips form-tips-ok");
		 return true;
	}
}

function checkCity(){
	var checkObj = $("#s_city");
	var province =checkObj.val();
	var _tips =  $("#pcTips");
	if(province==''){
		checkObj.addClass("ipt-txt-error");
		 _tips.html(checkObj.attr("tips"));
		 _tips.removeClass().addClass("form-tips form-tips-error");
	 	return false;
	}else{
		 _tips.html("");
		 checkObj.removeClass("ipt-txt-error");
		 _tips.removeClass().addClass("form-tips form-tips-ok");
		 return true;
	}
}



/**
* 保存职位信息
*/
function saveJob(){
	if(checkUser()&&validate()){
		//提交服务器
		var options = {
			dataType:'json',
		 	success: function(data) {
		 		if(403==data){
					openLogin();
				}else if('200'==data.back){
					if(data.hasJobs>0){
						$("#hasJobDiv").html(data.hasJobs);
						$("#job_yes_div").css({"display":"block"});
						fn_pop.maskShow();
					}else{
						$("#job_no_div").css({"display":"block"});
						fn_pop.maskShow();
					}
				}else if('-2'===data.back){
					asyncbox.alert("今日发布职位数已达上限，请明日再试");	    	
					$("#saveDiv").html("<span class='fn-cgray fn-ml20'>今日发布职位数已达上限，请明日再试</span>");
				}else{
					asyncbox.alert("发布失败，请稍后再试");	    		
				}
			}
		};
		$("#jobForm").ajaxSubmit(options);
	}
}


/**
* 更新职位信息
*/
function updateJob(){
	if(checkUser()&&validate()){
		//提交服务器
		var options = {
			dataType:'json',
		 	success: function(data) {
		 		if(403==data){
					openLogin();
				}else if('200'==data.back){
					//asyncbox.alert("更新成功");	   
					//初始化定时器3秒后关闭
					closeTipsPop($("#save_ok_div"),3);
				}else{
					//初始化定时器3秒后关闭
					closeTipsPop($("#save_no_div"),3);
				}
			}
		};
		$("#jobForm").ajaxSubmit(options);
	}
}